package com.scan.bus.util;

import android.content.Context;
import android.media.MediaPlayer;

import java.io.IOException;

public class Mp3MediaPlayUtil {
    private static MediaPlayer player;

    public static void play(Context context, int resource) {
        try {
            if (player == null) {
                player = MediaPlayer.create(context, resource);//这里的音频名要和raw的音频名相同
            }
            if (player != null) {
                player.stop();
                player.prepare();// 同步
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (player != null) {
            player.start();
        }
    }
}
